Skip to content

bpo-38724: Implement subprocess.Popen.__repr__#17151

Merged
taleinat merged 9 commits into
python:masterfrom
dorosch:implement-subprocess.Popen.__repr__
Nov 17, 2019
Merged

bpo-38724: Implement subprocess.Popen.__repr__#17151
taleinat merged 9 commits into
python:masterfrom
dorosch:implement-subprocess.Popen.__repr__

Conversation

@dorosch

@dorosch dorosch commented Nov 14, 2019

Copy link
Copy Markdown
Contributor

@dorosch
dorosch requested a review from gpshead as a code owner November 14, 2019 10:30
@the-knights-who-say-ni

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@dorosch

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@cool-RR cool-RR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

I think that the PID by itself is not useful enough for identifying what's going on. I'd suggest including the args (truncated if they're beyond a certain length) and the return code if the process is finished.

Also, tests.

@dorosch

dorosch commented Nov 14, 2019

Copy link
Copy Markdown
Contributor Author

@cool-RR Thanks for your review. Could you tell me where I can find the necessary value for length args (or where can I set variable for maximum length args)?

@cool-RR cool-RR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, I left a bunch of comments.

Comment thread Lib/subprocess.py Outdated
Comment thread Lib/subprocess.py Outdated
Comment thread Lib/subprocess.py Outdated
Comment thread Lib/subprocess.py Outdated
Comment thread Lib/test/test_subprocess.py Outdated
Comment thread Lib/test/test_subprocess.py Outdated
Comment thread Lib/test/test_subprocess.py Outdated
Comment thread Lib/test/test_subprocess.py Outdated

@cool-RR cool-RR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@dorosch

dorosch commented Nov 15, 2019

Copy link
Copy Markdown
Contributor Author

Looks good to me!

Thanks for your code review)

@taleinat taleinat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! It is certainly in the right direction :)

Comment thread Lib/subprocess.py Outdated
Comment thread Lib/subprocess.py Outdated
Comment thread Lib/subprocess.py Outdated
Comment thread Lib/test/test_subprocess.py Outdated
Comment thread Misc/NEWS.d/next/Library/2019-11-14-14-13-29.bpo-38724.T5ySfR.rst Outdated
Comment thread Lib/subprocess.py Outdated
@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@dorosch

dorosch commented Nov 15, 2019

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@brandtbucher brandtbucher added the type-feature A feature request or enhancement label Nov 15, 2019

@taleinat taleinat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes so quickly!

This is in the right direction but I have a few more requests.

Comment thread Lib/subprocess.py Outdated
Comment thread Lib/subprocess.py Outdated

return (
f"<{self.__class__.__name__}: "
f"returncode:'{self.returncode}' args:'{args}'>"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return code should not be surrounded by quotes: it will be either an integer or None, but never a string.

I'm not sure about args, but if we go with putting quotes around it, that would be interpreted as being a string literal, so we should use its repr, i.e. args:{args!r}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree regarding the return code.

Also regarding the args: I suggested map(shlex.quote, args) but I know there's also subprocess.list2cmdline which has different results. I picked the former arbitrarily, if you have reason to prefer the latter, go for it.

In any case, @dorosch should definitely remove the quotes he included and use !r as you suggested.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that list2cmdline() is only for use on Windows!!

It may be wise to use it if _mswindows is true, falling back to ' '.join(map(shlex.quote, args)) otherwise.

Or just print the args as a list and avoid the whole issue:

f'<Popen: ... args: {list(self.args)!r}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that list2cmdline() is only for use on Windows!!

That was worth knowing! Thanks.

In that case, my recommendation is to stay with the shlex code that's in the PR. I'd avoid printing the args as a list, it's always annoying to see these lists when debugging. (Of course, they should always be used when calling subprocess functions.)

@taleinat taleinat Nov 16, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, command lines are easier to read when not written as lists. On the other hand, a list matches the interface of the Popen() constructor and the internal representation, is not platform-dependent, and is unambiguous.

It's a good sign that everything is settling down and we're left just with "bike-shedding" ;) The proper place for this discussion would be the bug tracker. Care to bring this up there, @cool-RR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, it's indeed bikeshedding and we can let it go. After removing the shlex imports, this PR is good to go.

Comment thread Lib/test/test_subprocess.py Outdated
@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@taleinat taleinat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of the shlex imports are no longer necessary.

Other than that, is LGTM!

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@dorosch

dorosch commented Nov 17, 2019

Copy link
Copy Markdown
Contributor Author

Both of the shlex imports are no longer necessary.

Other than that, is LGTM!

Thank you for your comment

@dorosch

dorosch commented Nov 17, 2019

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@taleinat taleinat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@taleinat

Copy link
Copy Markdown
Contributor

@gpshead, @giampaolo, want to take a look at this before it goes in?

@giampaolo giampaolo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good change.

@taleinat

Copy link
Copy Markdown
Contributor

Thanks for the extra review @giampaolo!

@taleinat
taleinat merged commit 645005e into python:master Nov 17, 2019
@taleinat

Copy link
Copy Markdown
Contributor

Also, thanks @cool-RR for the original suggestion and for the code reviews here!

jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants